(function(){
	window.WindowManager={
		toggleMaximized:function(){try{	
			if(top.windowState!=3)
				listeners.send("win-windowed-start");
			else
				listeners.send("win-maximize-start");
		}catch(e){trace(e);}},
		
		enterMaximized:function(){try{
			top.maximize();
		}catch(e){trace(e);}},
		
		exitMaximized:function(){try{
			top.restore();
		}catch(e){trace(e);}},
		
		minimize:function(){try{
			top.minimize();
		}catch(e){trace(e);}},
		
		close:function(){try{
			top.close();
		}catch(e){trace(e);}},
	};
	
	listeners.add("win-maximize-start",function(){
		WindowManager.enterMaximized();
		listeners.send("win-maximize-done");
	},Infinity);
	
	listeners.add("win-windowed-start",function(){
		WindowManager.exitMaximized();
		listeners.send("win-windowed-done");
	},Infinity);
	
	listeners.add("win-minimize-start",function(){
		WindowManager.minimize();
		listeners.send("win-minimize-done");
	},Infinity);
	
	listeners.add("win-maximize-toggle",function(){
		WindowManager.toggleMaximized();
	},Infinity);
	
	listeners.add("win-close-start",function(){
		WindowManager.close();
		listeners.send("win-close-done");
	},Infinity);
	
	window.hooks.winMaximize=function() listeners.send("win-maximize-start");
	window.hooks.winWindowed=function() listeners.send("win-windowed-start");
	window.hooks.winMinimize=function() listeners.send("win-minimize-start");
	window.hooks.winMaximizedToggle=function() listeners.send("win-maximize-toggle");
	window.hooks.winClose=function() listeners.send("win-close-start");
	
})();